// stringtools.h
//
// String tools

#include "stringTools.h"

namespace simple{
    //
    // StringTools
    //
    // Standard terminators for parsing a text stream
    // Note. The first character in the string is a space
    std::string StringTools::sStandardTerm = " \t\r\n";


    Token StringTools::sParse (const std::string& str, const std::string& term)
    {
        Token result;

        // Skip over leading terminators
        size_t start = str.find_first_not_of (term);
        if (start == str.npos) {
            // The entire string only contains terminator characters
            return result;
        }

        // Find the first command
        size_t end = str.find_first_of (term, start);
        if (end == str.npos) {
            result.parsed = str;
            return result;
        }

        // Extract the first command
        result.parsed = str.substr (start, end-start);

        // Return the rest of the string (after the terminators)
        size_t next = str.find_first_not_of (term, end);
        if (next != str.npos)
            result.remainder = str.substr (next);

        return result;
    }
}